#-*- coding: utf8 -*-

from tutor.scripts import *
from tutor.plugins.sympy import *

while True:
    with display_block('Entradas'):
        x1 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
        x2 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
        y1 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
        y2 = One * oneof(0, 0, 1, 2, 3) * oneof(1, -1)
        x1, x2 = min(x1, x2), max(x1, x2)
        y1, y2 = min(y1, y2), max(y1, y2) 
        sigma0 = symbols('sigma_0', each_char=False)
        upper_t = oneof(True, False)
        P1 = (x1, y1)
        P2 = (x1, y2)
        P3 = (x2, y2)
    if x1 == x2 or y1 == y2:
        continue

    with display_block('Variáveis auxiliares'):
        reta = y1 + (x - x1) * (y2 - y1) / (x2 - x1)
        reta2 = solve(y - reta, x)[0]

    with display_block('Respostas'):
        res = (y**2).integrate([y, reta, y2])
        res = res.integrate([x, x1, x2])
        inerciaX = correta = together(res * sigma0)
        
        res = (x**2).integrate([y, reta, y2])
        res = res.integrate([x, x1, x2])
        inerciaY = together(res * sigma0)
        inerciaZ = inerciaX + inerciaY

        res = (y**2).integrate([x, x1, x2])
        res = res.integrate([y, y1, y2])
        quadradoX = together(res * sigma0)

        res = (x**2).integrate([x, x1, x2])
        res = res.integrate([y, y1, y2])
        quadradoY = together(res * sigma0)
        quadradoz = quadradoX + quadradoY

        dis1 = together((quadradoX + correta)/2)
        dis2 = together((inerciaX + inerciaY)/2)
        del res
    break
